package com.lm.geode.service;

import com.lm.geode.entry.User;
import com.lm.geode.repository.UserRepository;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Cacheable(value = "Users", key = "#id")
    public User getUserById(Long id) {
        System.out.println("从数据库加载用户：" + id);
        return userRepository.findById(id).orElse(null);
    }
}